const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Printer = sequelize.define('Printer', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false
  },
  ip: {
    type: DataTypes.STRING,
    allowNull: false,
    // 移除唯一性约束，允许多个打印机使用相同IP
    // unique: true
  },
  port: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 9100
  },
  protocol: {
    type: DataTypes.STRING,
    allowNull: false,
    defaultValue: 'RAW',
    validate: {
      isIn: [['RAW', 'IPP']]
    }
  },
  enableColor: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false
  },
  description: {
    type: DataTypes.STRING,
    allowNull: true
  },
  isOnline: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false
  },
  taskCount: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0
  },
  lastOnline: {
    type: DataTypes.DATE,
    allowNull: true
  },
  todayPrintCount: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0
  },
  failedPrintCount: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0
  },
  isSystemPrinter: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false
  }
}, {
  timestamps: true
});

module.exports = { Printer }; 